Page({
    data: {
    remind: '加载中',
    help_status: false,
    userid_focus: false,
    passwd_focus: false,
    phone:'',
    code:'',
    disable:true
  },
    onLoad: function (options) {
      var that = this
      wx.getUserInfo({
        success: function (res) {
          console.log(res)
          var userInfo = res.userInfo
          var nickName = userInfo.nickName
          var avatarUrl = userInfo.avatarUrl
          var gender = userInfo.gender //性别 0：未知、1：男、2：女
          var province = userInfo.province
          var city = userInfo.city
          var country = userInfo.country
          that.setData({
            userImg: avatarUrl,
            nickName: nickName
          })
        }
      })
    },
  onReady: function(){
    var _this = this;
    setTimeout(function(){
      _this.setData({
        remind: ''
      });
    }, 1000);
  },
  confirmTel:function(e){
    let tel = e.detail.value;
    console.log(!/^1[34578]\d{9}$/.test(tel))
    if (!(/^1[34578]\d{9}$/.test(tel))) {
      wx.showToast({
        title: '请输入正确的手机号码',
        icon: 'none',
        duration: 2000
      })
    }
    this.setData({
      phone:tel
    })
  },
  confirmCode:function(e){
    let codeInput = e.detail.value
    console.log(codeInput)
    console.log(this.data.phone)
    if (codeInput != '' && this.data.phone != ''){
      this.setData({
        disable:false
      })
    }
  },
  submitInfo: function (e) {
    console.log(e)
    let tel = e.detail.value.tel
    let code = e.detail.value.code
    if (!(/^1[34578]\d{9}$/.test(tel))){
      wx.showToast({
        title: '请输入正确的手机号码',
        icon:'none',
        duration:2000
      })
      return false
    }
    if (code == '') {
      wx.showToast({
        title: '请输入验证码',
        icon: 'none',
        duration: 2000
      })
      return
    }
    let token = wx.getStorageSync('token')
    let userId = wx.getStorageSync('userId')
    let params = {
      field:'cellphone',
      value: tel
    }
    wx.request({
      url: 'https://qili.docdic.com/api/user/' + userId+ '?token='+token,
      method:'post',
      data:params,
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:function(res){
        console.log(res)
        if(Number(res.data.status) === 201){
          wx.showToast({
            title: '登录成功',
            icon: 'success',
            duration: 1000
          })
          setTimeout(()=>{
            wx.switchTab({
              url: "../works/index"
            })
          },1000)
        }
      }
    })
    },
     onShareAppMessage: function () {
        return {
        title: '我的工厂',
        desc: '我的工厂',
        path: '/pages/works/works'
        }
  }
})